package com.winit.util;

import com.mysql.fabric.proto.xmlrpc.XmlRpcClient;

/**
 * Created by wangjian on 17/6/15.
 */
public class Client_fabric {
    public static void main(String args[]) throws Exception {
        String hostname = ConfigUtil.getValue("mysql.fabric.hostname");
        String port = ConfigUtil.getValue("mysql.fabric.port");
        String user = ConfigUtil.getValue("mysql.fabric.client.user");
        String password = ConfigUtil.getValue("mysql.fabric.client.password");

        XmlRpcClient fabricClient = new XmlRpcClient("http://" + hostname + ":" + port, user, password);
        System.out.println("Fabrics: " + fabricClient.getFabricNames());
        System.out.println("Groups: " + fabricClient.getGroupNames());
        for (String groupName : fabricClient.getGroupNames()) {
            System.out.println("Group def for '" + groupName + "': " + fabricClient.getServerGroup(groupName).toString().replaceAll("Serv", "\n\tServ"));
        }
        System.out.println("Servers for fabric_test.a.1: " + fabricClient.getServersForKey("fabric_test.a", 1));
        System.out.println("Servers for fabric_test.a.2: " + fabricClient.getServersForKey("fabric_test.a", 3));
        System.out.flush();
        System.out.println("All servers: " + fabricClient.getServerGroups());
    }
}
